package cn.edu.nju.software.fantasyCard.screens;

import cn.edu.nju.software.fantasyCard.MainGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;

/**
 *   创建者：            杨光 
 *   创建时间：        2014-2-26   上午11:26:00  
 */

public class MainMenuScreen implements Screen {

	MainGame mainGame;
	Stage stage;
	
	public MainMenuScreen(MainGame mainGame) {
		this.mainGame = mainGame;
	}
	
	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	    stage.act(Gdx.graphics.getDeltaTime());
	    stage.draw();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub

	}

	@Override
	public void show() {
		stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); 
		Gdx.input.setInputProcessor(stage);
		
		Table table = new Table();
		table.setFillParent(true);
		stage.addActor(table);		
		Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
		
		Label nameLabel = new Label("选择角色", skin);
		SelectBox selectPlayer = new SelectBox(new String[] {"儒", "道", "妖"}, skin);
		Image palyerImg = new Image(new Texture(Gdx.files.internal("data/palyer.jpg")));
		//palyerImg.scale(-0.2f);
		TextureRegion upRegion = skin.getRegion("default-slider-knob");
		TextureRegion downRegion = skin.getRegion("default-slider-knob");
		BitmapFont buttonFont = skin.getFont("default-font");
		TextButton cardsButton = new TextButton("我的卡牌", skin);
		cardsButton.addListener(new InputListener() {
			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
				mainGame.setScreen(new MyCardsScreen(mainGame));
				return false;
			}
		});
		TextButton playButton = new TextButton("对战", skin);
		playButton.addListener(new InputListener() {
			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
				mainGame.setScreen(new GameScreen(mainGame));
				return false;
			}
		});
		TextButton backButton = new TextButton("返回", skin);
		backButton.addListener(new InputListener() {
			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
				mainGame.setScreen(new LogInScreen(mainGame));
				return false;
			}
		});
		
		table.add(nameLabel);
		table.add(selectPlayer);
		table.row();
		table.add(palyerImg);
		//table.row();
		table.add(cardsButton);
		table.add(playButton);
		table.row();
		table.add(backButton);
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		stage.dispose();
	}

}


